//
//  DishOrdersCell.m
//  OrderSeat
//
//  Created by 王威 on 13-12-4.
//  Copyright (c) 2013年 wangwei. All rights reserved.
//

#import "DishOrdersCell.h"

@implementation DishOrdersCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setContent:(NSMutableDictionary *)dic allDishs:(NSArray *)dishList
{
    self.dictionary = dic;
    self.dishList = dishList;
    
    NSString *orderTime = [dic objectForKey:@"order_time"];
    NSString *zaowan = [dic objectForKey:@"zaowan"];
    NSString *zongjia = [dic objectForKey:@"zongjia"];
    NSString *fenshu = [dic objectForKey:@"fenshu"];
    NSString *tname = [dic objectForKey:@"tname"];
    NSString *dinnerTime = [NSString stringWithFormat:@"%@ %@",orderTime,zaowan];
    
    int selected = [[dic objectForKey:@"selected"] intValue];
    
    _dinnerTimeLabel.text = dinnerTime;
    [_dinnerTimeLabel autoWidthForSingleLine];
    
    _totalCountLabel.text = [NSString stringWithFormat:@"%@份/",fenshu];
    [_totalCountLabel autoWidthForSingleLine];
    
    _totalPriceLabel.text = [NSString stringWithFormat:@"￥%@",zongjia];
    if (tname) _totalPriceLabel.text = [NSString stringWithFormat:@"%@",tname];
    
    [_totalPriceLabel autoWidthForSingleLine];
    
    _totalCountLabel.left = _dinnerTimeLabel.right_10;
    _totalPriceLabel.left = _totalCountLabel.right;
    
    _selectBtn.selected = selected == 1;
    
    [self addTarget:self action:@selector(selectAction:)];
}

- (IBAction)selectAction:(id)sender
{
    int selected = [[_dictionary objectForKey:@"selected"] intValue];
        
    selected = selected == 0 ? 1 : 0;
    [_dictionary setObject:INT_TO_STR(selected) forKey:@"selected"];
    
    for (NSMutableDictionary *dic in _dishList) {
        if (![dic isEqualToDictionary:_dictionary]) {
            [dic setObject:@"0" forKey:@"selected"];
        }
    }
    
    if (_delegate) {
        [_delegate selectFinished:_dictionary];
    }
}

@end
